﻿using System;
using System.Collections.Generic;
using System.Text;

using NGE;

namespace MH.MENU
{
    public class Save : Panelbox
    {
        public Save(Game g)
            : base(g)
        {
            Name = "保存";

            Location = new Microsoft.DirectX.Vector3(120, 120, 0);
            Size = new System.Drawing.Size(80, 80);
            //BGColor = System.Drawing.Color.Gray;

            slot0 = new Buttonbox();
            slot0.Textbox.Text = "服务器";
            slot0.Location = new Microsoft.DirectX.Vector3(0, 0, 0);
            slot0.OnButtonboxEvent += new MenuEvent(slot0_OnButtonboxEvent);

            AddElement(slot0);

            slot1 = new Buttonbox();
            slot1.Textbox.Text = "本地A";
            slot1.Location = new Microsoft.DirectX.Vector3(0, 20, 0);
            slot1.OnButtonboxEvent += new MenuEvent(slot1_OnButtonboxEvent);

            AddElement(slot1);

            slot2 = new Buttonbox();
            slot2.Textbox.Text = "本地B";
            slot2.Location = new Microsoft.DirectX.Vector3(0, 40, 0);
            slot2.OnButtonboxEvent += new MenuEvent(slot2_OnButtonboxEvent);

            AddElement(slot2);

            slot3 = new Buttonbox();
            slot3.Textbox.Text = "本地C";
            slot3.Location = new Microsoft.DirectX.Vector3(0, 60, 0);
            slot3.OnButtonboxEvent += new MenuEvent(slot3_OnButtonboxEvent);

            AddElement(slot3);

        }

        SceneComponent sceneCOM
        {
            get
            {
                return ((SceneComponent)game.GetComponent("SceneCOM"));
            }
        }
        ScriptComponent scriptCOM
        {
            get
            {
                return ((ScriptComponent)game.GetComponent("ScriptCOM"));
            }
        }

        void slot0_OnButtonboxEvent(object sender, object arg)
        {
            ButtonboxState bs = (ButtonboxState)arg;
            if (bs == ButtonboxState.Up)
            {
                //scriptCOM.AS("menu return " + give.Textbox.Text + "\nmenu close", false);
            }
        }
        void slot1_OnButtonboxEvent(object sender, object arg)
        {
            ButtonboxState bs = (ButtonboxState)arg;
            if (bs == ButtonboxState.Up)
            {
                save("cpa.ncp");
            }
        }
        void slot2_OnButtonboxEvent(object sender, object arg)
        {
            ButtonboxState bs = (ButtonboxState)arg;
            if (bs == ButtonboxState.Up)
            {
                save("cpb.ncp");
            }
        }
        void slot3_OnButtonboxEvent(object sender, object arg)
        {
            ButtonboxState bs = (ButtonboxState)arg;
            if (bs == ButtonboxState.Up)
            {
                save("cpc.ncp");
            }
        }

        void save(string filename)
        {
            SceneComponent sc = ((SceneComponent)game.GetComponent("SceneCOM"));
            sc.PC.UnmontEventHandler();
            CheckPoint cp = new CheckPoint(sc.PC);
            Util.SaveObject(filename, cp);
            sc.PC.MountEventHandler(sc.OnPlayerCharacterActCode);
            game.MenuCOM.Close();
        }

        Buttonbox slot0;
        Buttonbox slot1;
        Buttonbox slot2;
        Buttonbox slot3;
    }
}
